package com.yueqian.system.controller;

import java.util.List;

import javax.annotation.Resource;

import org.springframework.web.bind.annotation.*;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.yueqian.framework.entity.ResultEntity;
import com.yueqian.framework.entity.VerifyCodeEntity;
import com.yueqian.system.service.SystemUserService;
import com.yueqian.system.vo.req.UserReqVO;
import com.yueqian.system.vo.res.UserInfoResVO;
import com.yueqian.system.vo.res.UserResVO;

@RestController
@RequestMapping("/user")
public class UserController {

	@Resource
	private SystemUserService userService;


	@PostMapping("/register")
	public ResultEntity<Boolean> register(@RequestBody UserReqVO UserReqVO) throws Exception {
		return ResultEntity.success(userService.register(UserReqVO.getUsername(), UserReqVO.getPassword()));
	}

	@PostMapping("/login")
	public ResultEntity<String> login(@RequestBody UserReqVO UserReqVO) throws Exception {
		return ResultEntity.success(userService.login(UserReqVO));
	}

	@GetMapping("/generateVerifyCode")
	public ResultEntity<VerifyCodeEntity> generateVerifyCode() {
		return ResultEntity.success(userService.generateVerifyCode());
	}


	@GetMapping("/getInfo")
	public ResultEntity<UserInfoResVO> getInfo(@RequestParam(value = "token") String token) {
		return ResultEntity.success(userService.getInfo(token));
	}

	@GetMapping("/logout")
	public ResultEntity<String> logout(@RequestParam(value = "token") String token) {
		return ResultEntity.success(userService.logout(token));
	}

	@GetMapping("/selectPageData")
	public ResultEntity<IPage<UserResVO>> selectPageData(UserReqVO reqVO) {
		return ResultEntity.success(userService.selectPageData(reqVO));
	}

	@PostMapping("/editStatus")
	public ResultEntity<Boolean> editStatus(@RequestBody UserReqVO reqVO) {
		userService.editStatus(reqVO);
		return ResultEntity.ok(true);
	}


	@GetMapping("/delete")
	public ResultEntity<Boolean> delete(@RequestParam(value = "ids") List<Long> ids) {
		return ResultEntity.success(userService.delete(ids));
	}

	@PostMapping("/restPassword")
	public ResultEntity<Boolean> restPassword(@RequestBody UserReqVO reqVO) {
		userService.restPassword(reqVO);
		return ResultEntity.ok(true);
	}


	@GetMapping("/getDetail")
	public ResultEntity<UserResVO> getDetail(@RequestParam(value = "id", required = false) Long id) {
		return ResultEntity.ok(userService.getDetail(id));
	}

	@PostMapping("/add")
	public ResultEntity<Long> add(@RequestBody UserReqVO reqVO) {
		return ResultEntity.success(userService.add(reqVO));
	}

}
